package org.androidannotations.gradle.view.fragment;

import android.app.Fragment;
import android.content.Intent;
import android.widget.ListView;
import android.widget.Toast;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.gradle.R;
import org.androidannotations.gradle.controller.DemoController;
import org.androidannotations.gradle.view.adapter.DemoListAdapter;
import org.androidannotations.gradle.view.model.DemoListItemVo;
import org.androidannotations.gradle.view.model.DemoListVo;

/**
 * Created by ir on 2015/5/6.
 */
@EFragment(R.layout.demo_list_fragment)
public class DemoListFragment extends Fragment {

    @ViewById
    ListView listView;

    @Bean
    DemoListAdapter adapter;

    @Bean
    DemoListVo model;

    @Bean
    DemoController controller;

    @AfterViews
    void afterViews() {
        model.setItemList(controller.findDemoList());
        adapter.setData(model);
        listView.setAdapter(adapter);
    }

    @ItemClick
    void listViewItemClicked(DemoListItemVo demoListItem) {
        Intent intent = new Intent();
        intent.setClass(getActivity().getApplicationContext(), demoListItem.getActivityClass());
        startActivity(intent);
    }
}
